#!/bin/bash

source /opt/rh/devtoolset-8/enable 

# build python2.7.15/python3.6.6, 需要动态编译, 因为vim8.2只能加载动态库
cd ~/tools
# wget https://www.python.org/ftp/python/2.7.15/Python-2.7.15.tar.xz
# tar xvf Python-2.7.15.tar.xz
# cd Python-2.7.15
# ./configure --enable-shared --prefix=/usr
# make -j8
# su root -c "make install"

# wget https://www.python.org/ftp/python/3.6.6/Python-3.6.6.tar.xz
cd ~/tools
tar xvf Python-3.6.6.tar.xz
cd Python-3.6.6
# ./configure --enable-shared --prefix=/usr
./configure
make -j8
su root -c "make install"

# build vim-v8.2.0766.tar.gz
cd ~/tools
tar zxvf vim-v8.2.0766.tar.gz
cd vim
git co .
./configure --enable-pythoninterp=yes --enable-python3interp=yes
make -j8
su root -c "make install"

# build llvm-clang
# wget https://github.com/llvm/llvm-project/releases/download/llvmorg-11.0.0/llvm-11.0.0.src.tar.xz
# wget https://github.com/llvm/llvm-project/releases/download/llvmorg-11.0.0/clang-11.0.0.src.tar.xz
# wget https://github.com/llvm/llvm-project/releases/download/llvmorg-11.0.0/compiler-rt-11.0.0.src.tar.xz

cd ~/tools
tar xvf llvm-11.0.0.src.tar.xz
tar xvf clang-11.0.0.src.tar.xz
tar xvf compiler-rt-11.0.0.src.tar.xz

mv compiler-rt-11.0.0.src llvm-11.0.0.src/projects/compiler-rt
mv clang-11.0.0.src llvm-11.0.0.src/tools/clang

mkdir build_llvm; cd build_llvm
# cmake -DCMAKE_INSTALL_PREFIX=./install -DCMAKE_BUILD_TYPE=Release -G "Unix Makefiles" ../llvm-11.0.0.src
# make -j8;make -j8 install

# build ycm_core
# cd  ~/.vim/bundle
# git@gitee.com:Onmyway1988/YouCompleteMe.git
# cd YouCompleteMe
# git submodule update --init --recursive
 cd ~/tools
 mkdir build_ycm; cd build_ycm
 cp ../build_llvm/install/lib/libclang.so.11 .
 cmake -G "Unix Makefiles" -DEXTERNAL_LIBCLANG_PATH=./libclang.so.11 . ~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/
 make -j8
 mv ./libclang.so.11 ~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/

 cd ~/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/watchdog_deps/watchdog/
 python3 setup.py build --build-base=build/3 --build-lib=build/lib3

 cd ~/tools
